package com.sishu.utils;

import com.github.pagehelper.PageInfo;
import lombok.Data;
import org.springframework.stereotype.Component;

import java.io.Serializable;
import java.util.List;

/**
 * @author Li
 * @create 2020-06-29 9:59
 */

/**
 * 返回结果包装类
 * @param <T>
 */
@Component
@Data
public class Result<T> implements Serializable {

    /**
     * 返回状态码
     */
    private Integer code;

    /**
     * 异常信息显示
     */
    private String msg;

    /**
     * 数据摆放位置
     */
    private String position;

    /**
     *返回需要分页的集合
     */
    private PageInfo<T> result;
    /**
     *返回不需要分页的集合
     */
    private List<T> list;

    /**
     * 新增成功或者失败都需要返回字段：true&false
     */
    private Object data;

    private boolean isSuccess;

    public Result() {
    }

    public Result(Integer code, String position, String msg, Object data, boolean isSuccess) {
        this.code = code;
        this.position = position;
        this.msg = msg;
        this.data = data;
        this.isSuccess = isSuccess;
    }


    public Result(Integer code, String msg, boolean isSuccess) {
        this.code = code;
        this.msg = msg;
        this.isSuccess = isSuccess;
    }

    public Result(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Result(Integer code, String position, List<T> list, String msg, boolean isSuccess) {
        this.code = code;
        this.position = position;
        this.list = list;
        this.msg = msg;
        this.isSuccess = isSuccess;
    }

    public Result(Integer code, String position, PageInfo<T> result, String msg, boolean isSuccess) {
        this.code = code;
        this.position = position;
        this.result = result;
        this.msg = msg;
        this.isSuccess = isSuccess;
    }
}
